module.exports = function (app,models,$,db,nm){
    app.get('/v1/address',(req,res) => {
		var query = {
			pageSize:req.query.pageSize || 10,
			pageNum:req.query.pageNum || 1,
			unitId:req.unitId
		}
	
		models.address.list(query, ret => {
			res.send(ret)
		},{
			projection: {
				_id:1,
				memberId:1,
				receiver:1,
				phone:1,
				city:1,
				area:1,
				isDefault:1
			}
		})
	})
	//获取文章详情
	app.get("/v1/addressInfo", (req, res) => {
		if (req.query._id) {
		  models.address.find(
			{ _id: req.query._id },
			(ret) => {
			  res.send(ret);
			}
		  );
		} else {
		  res.send({ errorMsg: "请传入_id" });
		}
	  });
   	//新增
	app.post('/v1/address',(req,res) => {
		req.body.unitId = req.unitId
		models.address.insert(req.body, ret => {
			res.send(ret)
		})
	})

    //修改
	app.put('/v1/address',(req,res) => {
		models.address.update({_id:req.body._id},req.body, ret => {
			res.send(ret)
		})
	})

    //删除
	app.delete('/v1/address',(req,res)=>{
		models.address.remove({_id:req.query._id},ret=>{
			res.send(ret)
		},{real:true})
	})
}